/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2012
 */

package com.tudou.searchcontrol.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tudou.searchcontrol.model.Playsource;
import com.tudou.searchcontrol.model.PageInfo;
import com.tudou.searchcontrol.service.IPlaysourceService;



@Controller
@RequestMapping("/playsource/*")
public class PlaysourceAction extends BaseAction{

	@Autowired
	private IPlaysourceService playsourceService;
	
	@RequestMapping("list")
	public String list(HttpServletRequest request, HttpServletResponse response, ModelMap model,Playsource playsource,PageInfo pageInfo){
		Map searchMap = new HashMap();
		pageInfo =playsourceService.getPlaysourceByPage(searchMap,pageInfo);
		
		model.put("PageInfo", pageInfo);
		model.put("searchMap", searchMap);

		return "/playsource/playsourceList";
	}
	
	@RequestMapping("view")
	public String view(HttpServletRequest request, HttpServletResponse response, ModelMap model,Long id){
		Playsource playsource = playsourceService.getPlaysourceById(id);
		model.put("machineSetting", playsource);
		return "/playsource/playsourceView";
	}
	
	
	@RequestMapping("edit")
	public String edit(HttpServletRequest request, HttpServletResponse response, ModelMap model,Playsource playsource){
		if(playsource.getId() != null){
			playsource = playsourceService.getPlaysourceById(playsource.getId());
		}
		model.put("playsource", playsource);
		return "/playsource/playsourceEdit";
	}
	
	@RequestMapping("save")
	public String save(HttpServletRequest request, HttpServletResponse response, ModelMap model,Playsource playsource,PageInfo pageInfo){
		int i = playsourceService.saveOrUpdatePlaysource(playsource);
		
		Playsource newPlaysource = new Playsource();
		
		return this.list(request, response, model, newPlaysource,pageInfo);
	}
	
	
	@RequestMapping("delete")
	public String delete(HttpServletRequest request, HttpServletResponse response, ModelMap model,Playsource playsource,String delIds,PageInfo pageInfo){
		if(StringUtils.isEmpty(delIds)){
			delIds = playsource.getId().toString();
		}
		int i = playsourceService.deletePlaysource(delIds);
		
		Playsource newPlaysource = new Playsource();
		return this.list(request, response, model, newPlaysource,pageInfo);
	}
}